package com.yanqu.road.server.cmd.orewar.cross;

import com.yanqu.road.logic.config.GameConfig;
import com.yanqu.road.pb.orewar.OreWarProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.OreWarModule;
import com.yanqu.road.server.manger.activity.orewar.OreWarMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.property.Property;

import java.math.BigInteger;

@Cmd(code = Protocol.S_CROSS_ORE_WAR_GET_REWARD, desc = "跨服盐场领坑奖返回")
public class CrossGetRewardRespCmd extends AbstractCommand {


	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		OreWarProto.CrossOreGetRewardRespMsg crossRespMsg = OreWarProto.CrossOreGetRewardRespMsg.parseFrom(packet.getBytes());
		ret = crossRespMsg.getRet();


		OreWarProto.OreGetRewardRespMsg.Builder respMsg = OreWarProto.OreGetRewardRespMsg.newBuilder();
		respMsg.setActivityId(crossRespMsg.getActivityId());
		respMsg.setRet(ret);
		if(ret == 0){
			Property allProperty = new Property();
			allProperty.setGood(GameConfig.ACTIVITY_ORE_WAR_OUTPUT_GOODSID, BigInteger.valueOf(crossRespMsg.getOutputCount1()));

			//do-xx 加上盐场的收益，一并给用户发放
			Property reward = player.getModule(OreWarModule.class).getOccupyReward(crossRespMsg.getActivityId(),crossRespMsg.getLastGetTime(), 0);
			allProperty.addProperty(reward);
			OreWarMgr.addCrossGetReward(respMsg.getActivityId(),player,allProperty,crossRespMsg.getGroupId());

			respMsg.setLastGetTime(crossRespMsg.getLastGetTime());
			respMsg.setOutputCount1(allProperty.getCountByGoodsId(GameConfig.ACTIVITY_ORE_WAR_OUTPUT_GOODSID).longValue());
		}

		player.sendPacket(Protocol.U_ORE_WAR_GET_REWARD, respMsg);
	}

	@Override
	public void sendData(GamePlayer player) {

	}
}
